#include <iostream>
#include <vector>
#include <unordered_map>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
#define endl '\n'
const int N = 2e5 + 10;
int dp[N];

void solve() 
{
    int n; cin >> n;
    cin >> dp[1];
    int ans = -2e9;
    for(int i = 2; i <= n; i++)
    {
        int x; cin >> x;
        dp[i] = max(dp[i - 1] + x, x);
        ans = max(ans, dp[i]);
    }    
    cout << ans << endl;
}

int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int T = 1;
	// cin >> T;
	while(T--)
	{
        solve();
	}
	return 0;
}